<?php

namespace App\Http\Controllers\Msg;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
class MsgController extends Controller
{
    public function addcontent(){
        if(empty($_POST)){
            return view('msg.addcontent');
        }else{
            if(DB::table('msg')->insert(['tittle'=>$_POST['tittle'], 'content'=>$_POST['content']])){
                return 'success';
            }
        }
    }

    public function index(){
        $data = DB::table('msg')->get();
        return view('msg.index', ['msg'=>$data]);
    }

    public function delete($id){
        if(DB::table('msg')->where('id', $id)->delete()){
            return redirect('index');
        }
    }

    public function edit($id){
        $data = DB::table('msg')->where('id', $id)->first();
        return view('msg.edit', ['data'=>$data]);
    }
}
